﻿using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using DotNet.Utilities.ConsoleHelper;
using PropertyChanged;
using WPFPractice.Models;
using WPFPractice.Utils;
using WPFTemplateLib.WpfHelpers;

namespace WPFPractice.Windows
{
	/// <summary>
	/// WinControls.xaml 的交互逻辑
	/// </summary>
	public partial class WinControls : Window
	{
		public WinControls()
		{
			InitializeComponent();
			DataContext = new ControlsViewModel();
		}
	}

	[AddINotifyPropertyChangedInterface]
	public class ControlsViewModel : MyBindableBase
	{
		#region 绑定

		/// <summary>
		/// 表格数据
		/// </summary>
		public ObservableCollection<User> Datas { get; set; }

		#endregion

		#region Command

		/// <summary>
		/// 切换到新增模式命令
		/// </summary>
		public ICommand AddNewCmd { get; set; }

		#endregion

		public ControlsViewModel()
		{
			Console.SetOut(new ConsoleWriter(s =>
			{
				ShowInfoUc(s);
			}));

			SetCommandMethod();

			InitValueAsync();
		}

		/// <summary>
		/// 数据初始化
		/// </summary>
		private async Task InitValueAsync()
		{
			await Task.Delay(1);

			Console.WriteLine("演示 带 加载/移除 动画的列表");
			Datas = TestDataHelper.GetUsers();
		}

		/// <summary>
		/// 命令方法赋值(在构造函数中调用)
		/// </summary>
		private void SetCommandMethod()
		{
			AddNewCmd ??= new RelayCommand(o => true, o =>
			{
				
			});
		}
	}
}
